﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Data;
using System.Data.SqlClient;
using GPSTracker.Helper;
using System.Text;

namespace GPSTracker.Views.DAL
{
    public class AreaDAL
    {
        public DataTable FillAreaMasterGrid(string strAreaID)
        {
            var sb = new StringBuilder();
            var dt = new DataTable();

            if (strAreaID == string.Empty)
            {
                var strSQL = "SELECT * FROM dbo.VW_GetArea";
                var da = new SqlDataAdapter(strSQL, CommonFx.GetSqlCon());
                da.Fill(dt);
            }
            else
            {
                sb.Append("SELECT * FROM dbo.VW_GetArea WHERE AreaID = '" + strAreaID + "' ");
                var da = new SqlDataAdapter(sb.ToString(), CommonFx.GetSqlCon());
                da.Fill(dt);
            }
            return dt;
        }

        public void DeleteAreaMaster(string strAreaID)
        {
            var sb = new StringBuilder();
            sb.Append("DELETE dbo.M_Area WHERE AreaID = '" + strAreaID + "' ");

            var cmd = new SqlCommand(sb.ToString(), CommonFx.GetSqlCon());
            cmd.ExecuteNonQuery();
        }
    }
}
